package com.jhhc.Weathers.datasupplement.service.impl;

import com.jhhc.Weathers.datasupplement.dao.BdmsFbcResultADao;
import com.jhhc.Weathers.datasupplement.entity.BdmsFbcResultA;
import com.jhhc.Weathers.datasupplement.service.ZksgService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author LYQ
 */
@Service("ZksgService")
public class ZksgServiceImpl implements ZksgService {
    @Resource
    private BdmsFbcResultADao aDao;
    @Override
    public int insertBatch(List<BdmsFbcResultA> aList) {
        int num = 0;//insert插入总数量
        int count = 0;//insert插入数量
        int batchCount = 20;//每批commit的个数
        int batchLastIndex = batchCount - 1;// 每批最后一个的下标
        for (int index = 0; index < aList.size() -1;) {
            if(batchLastIndex > aList.size() - 1){
                batchLastIndex = aList.size() - 1;
                count = aDao.insertBatch(aList.subList(index,batchLastIndex + 1));
                num+=count;
                break;
            }else {
                count = aDao.insertBatch(aList.subList(index,batchLastIndex + 1));
                index = batchLastIndex + 1;
                batchLastIndex = index + (batchCount - 1);
            }
            num+=count;
            System.out.println("入库中");
        }
        return num;
    }
}
